# -*- coding: UTF-8 -*-

# 导入gzip模块
import gzip

# 导入流处理模块
import shutil

# 待压缩的文件
filename = './externalFile/data.txt'

# 压缩数据写入文件
compressFile = './externalFile/data.gz'

# 对文件进行压缩，生成一个压缩文件对象
with open(filename, 'rb') as f_in:
    with gzip.open(compressFile, 'wb') as f_out:
        # 写入压缩文件
        shutil.copyfileobj(f_in, f_out)